//
//  CreateJobInstallerDetailVCViewController.swift
//  GreenDeal
//
//  Created by Moennig Q on 2023/3/6.
//

import UIKit

class CreateJobInstallerDetailVC: BaseViewController {
    var editFlag: Bool = false//创建和Review的编辑共用此功能
    let customView = CreateJobInstallerDetailView(topBGImageName: "createjob_installdate_top_bg",useScrollViewFlag: true)
    override func viewDidLoad() {
        super.viewDidLoad()
        self.initUI()
        self.loadData()
    }
    //
    private func initUI(){
        self.view = self.customView
        self.customView.setTitleInfo(R.string.localizable.installerDetails())
    }
    private func loadData(){
        let service = MyInformationService()
        service.setBlockAfterNetwork { [weak self] (result, otherInfo) in
            guard let strongSelf = self else { return  }
            if let model = result as? MyInformationModel{
                //如果是installer就设置默认值
                if model.installer  && CreateJobModelHelper.shared.createJobViewModel.installerDetail.installerName == "" {
                    CreateJobModelHelper.shared.createJobViewModel.installerDetail.installerName = model.name
                    CreateJobModelHelper.shared.createJobViewModel.installerDetail.installerID = model.id
                }
                //如果是designer就设置默认值
                if model.designer && CreateJobModelHelper.shared.createJobViewModel.installerDetail.designerName == ""{
                    CreateJobModelHelper.shared.createJobViewModel.installerDetail.designerName = model.name
                    CreateJobModelHelper.shared.createJobViewModel.installerDetail.designerID = model.id
                }
                //如果是electrician就设置默认值
                if model.electrician  && CreateJobModelHelper.shared.createJobViewModel.installerDetail.electricianName == ""{
                    CreateJobModelHelper.shared.createJobViewModel.installerDetail.electricianName = model.name
                    CreateJobModelHelper.shared.createJobViewModel.installerDetail.electricianID = model.id
                }
                strongSelf.customView.setData(CreateJobModelHelper.shared.createJobViewModel.installerDetail)
            }
        } errorBlock: { code, error in
            
        }
        service.getMyInformation()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(true, animated: false)
    }
}
